package com.qlm.tongji.controller;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.qlm.interceptor.AuthInterceptor;
import com.qlm.tongji.service.IStatisticService;
import com.qlm.tongji.service.impl.StatisticServiceImpl;
import com.qlm.tools.DateUtils;
import com.qlm.tools.StringUtils;
import com.qlm.view.EchartDataView;

@Before(AuthInterceptor.class)
public class StatisticController extends Controller {

	protected final static Logger logger = LoggerFactory
			.getLogger(StatisticController.class);

	private IStatisticService statisticService = enhance(StatisticServiceImpl.class);

	public void scanRecordChart() {
		logger.info("method:StatisticController-scanRecordChart");
		// List<String> areaList = adminService.getAreaList();
		// setAttr("areaList", areaList);
		render("/page/tongji/scanRecordChart.jsp");
	}

	public void dayScanRecordChart() {
		logger.info("method:StatisticController-dayScanRecordChart");
		render("/page/tongji/dayScanRecordChart.jsp");
	}

	public void getSRECharts() {
		logger.info("method:StatisticController-getSRECharts");

		String startDate = getPara("startDate");
		String endDate = getPara("endDate");
		
		if(StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
			endDate=DateUtils.dateToString(DateUtils.PATTEN_YMD);
			startDate=DateUtils.dateToString(DateUtils.addDay(new Date(), -7),DateUtils.PATTEN_YMD);
		}

		EchartDataView dev = statisticService.getScanEDV(startDate, endDate);
		renderJson(dev);
	}
	
	public void getDSRECharts() {
		logger.info("method:StatisticController-getDSRECharts");
		EchartDataView dev = statisticService.getScanEDVOneDay();
		renderJson(dev);
	}
	
	public void hbRecordChart() {
		logger.info("method:StatisticController-scanRecordChart");
		// List<String> areaList = adminService.getAreaList();
		// setAttr("areaList", areaList);
		render("/page/tongji/hbRecordChart.jsp");
	}

	public void dayHbRecordChart() {
		logger.info("method:StatisticController-dayScanRecordChart");
		render("/page/tongji/dayHbRecordChart.jsp");
	}

	public void getHbSRECharts() {
		logger.info("method:StatisticController-getSRECharts");

		String startDate = getPara("startDate");
		String endDate = getPara("endDate");
		
		if(StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
			endDate=DateUtils.dateToString(DateUtils.PATTEN_YMD);
			startDate=DateUtils.dateToString(DateUtils.addDay(new Date(), -7),DateUtils.PATTEN_YMD);
		}

		EchartDataView dev = statisticService.getHbEDV(startDate, endDate);
		renderJson(dev);
	}
	
	public void getHbDSRECharts() {
		logger.info("method:StatisticController-getDSRECharts");
		EchartDataView dev = statisticService.getHbEDVOneDay();
		renderJson(dev);
	}
	
	
	
	
}
